
<?php 

   include('../../Connections/KRAPPERCON.php');
  	
	$buscar = false;
	$found = false;
   $idOrdTra='';
   $codCli='';
   $nomCli='';
   $otCli = '';
   $apell='';
   $nifCli ='';
   $dirCli = '';
   $codVeh='';
   $desMar='';
   $numMot='';
   $numPla='';
   $fecIniProg='';
   $fecFinProg='';
   $fecIniReal='';
   $fecFinReal='';   
   $fecdoc = '';
   $fecfac ='';
   $condv = '';
   $txtot = '';
   $edoOrdTra='';
   $idCentro='';
   $ctdComb = 0;
   
   $userId='';
   $fecReg='';
   
   $opc=getGet('opcion','');
   
   $fecIni=clearChar(getParam('fecIni',''));
   $fecFin=clearChar(getParam('fecFin',''));
   $fecIniProg1=clearChar( getParam('fecIniProg1','') );
   $fecIniProg2=clearChar( getParam('fecIniProg2','') );
   
  
   if( $opc>=1 ){
	   
       $idOrdTra=clearChar(getGet('idOrdTra',''));
	   $idOrdTra = str_replace("?","",$idOrdTra);
	   $buscar = true;
       $sql="call usp_obtDatosOrdtTrabjo('".$idOrdTra."')";
	   doEcho($sql);
	   $res = $mysqli->exeQuery($sql);
	   if($res){	
			while($row = $res->fetch_assoc()){
				$found = true;
				$codCli=$row['ClientID'];
				$nomCli=$row['ClientNom'];
				
				$nifCli = $row['ClientNif'];
				$dirCli = $row['ClientDirec'];
				
				$fecdoc = $row['OrdenTraFeEmi'];
				$apell=$row['ClientApePat']." ".$row['ClientApeMat'];
				$codVeh=$row['VehID'];
				$desMar=$row['MarcaTxt'];
				$numMot=$row['VehNroMot'];
	            $numPla=$row['VehPlaca'];
				$fecIniProg=$row['fecIniProg'];
                $fecFinProg=$row['fecFinProg'];
				
				$fecIniReal=$row['fecIniReal'];
				$fecFinReal=$row['fecFinReal'];
				
				$idCentro=$row['CentroID'];
				$edoOrdTra=$row['EstadoOrdenTra'];
				
				$fecReg=$row['OrdenTraFeCr'];
				$userId=$row['UserID'];
				
				$fecfac = $row['OrdFecFac'];
				$txtot = $row['TxtOrden'];
				$condv = $row['CondVenID'];
				$moneda = $row['MoneyID'];
				
				$otCli = $row['OrdenIDCli'];
				
				$ctdComb = $row['CtdComb'];
			}
			
			$res->close();
            $mysqli->check_result();
		}     
	   
   } 


  $arEstados=array( array('id'=>'1','Desc'=>'PENDIENTE'),
                    array('id'=>'2','Desc'=>'EN PROCESO'),
					array('id'=>'3','Desc'=>'LISTO PARA ENTREGA'),
					array('id'=>'4','Desc'=>'TERMINADO'),
					array('id'=>'0','Desc'=>'CANCELADO') 
				  );
					
 
   
?>

<input type="button" name="" onclick="nuevaOT()" id="btn-new-ot" value="Nuevo" />&nbsp;
<input type="button" onclick="editOT()" id="btn-edit-ot" value="Editar" />
&nbsp;
 <input type="button" name="" id="btn-save" value="Grabar" />&nbsp;
 <input type="button" name="btn_stk_ot" id="btn_fact_ot2" onclick="doOtMigo()" value="Descargar Stock" />
 <input type="button" name="" id="btn_fact_ot" onclick="saveFactOt()" value="Facturar OT" />&nbsp;
 &nbsp;<input type="text" placeholder='Nro.Orden' id="t_nro_ot"  maxlength="10" />
</div>

<form id="frmAdOrdTrab" name="frmAdOrdTrab" action="Mantenimientos/OrdTrabajo/adicionar.php" method="post">


<input type="hidden" name="strSv" id="strSv" />
<input type="hidden" name="Imp" id="Imp" />

<input type="hidden" name="opcion" id="opcion" value="<?php echo $opc; ?>" />
<input type="hidden" name="idOrdTra" id="idOrdTra" value="<?php echo $idOrdTra ?>" />
<input type="hidden" name="fecIni" id="fecIni" class="" value="<?php echo $fecIni ?>"  />
<input type="hidden" name="fecFin" id="fecFin" class="" value="<?php echo $fecFin?>" />

<input type="hidden" name="fecIniProg1" id="fecIniProg1" class="" value="<?php echo $fecIniProg1 ?>" />
<input type="hidden" name="fecIniProg2" id="fecIniProg2" class="" value="<?php echo $fecIniProg2 ?>" />

<input type="hidden" name="h_pagina" id="h_pagina" value="<?php echo getParam('h_pagina','1'); ?>" />
<input type="hidden"  name="title_h" id="title_h" value="<?php echo getParam('title_h',''); ?>"  />
<input type="hidden"  name="accion" id="accion" value="<?php echo getParam('accion',''); ?>"  />



<table width="100%" cellpadding="0" cellspacing="0">
 <?php 
	if ($found){
	?>
  <tr>
    <td colspan="4">
    <div class="subTit">
	<?php 
    echo 'Orden de Trabajo '. $idOrdTra.' creada por '.$userId.' el '.$fecReg;	
    ?>
    </div>    </td>
  </tr>
  <?php 
	}
	?>
<tr>
<td colspan="4">
<strong>Datos Generales</strong></td></tr>
       <tr>
         <td>Estado General :</td>
         <td>
           <select name="cb_sts_ot" id="cb_sts_ot" >
             <option value="1">PENDIENTE</option>
             <option value="2">EN PROCESO</option>
             <option value="3">LISTO  PARA ENTREGA</option>
             <option value="4">TERMINADO</option>
             <option value="0">CANCELADO</option>           
		           </select>         </td>
         <td><strong>Nro OT:</strong></td>
         <td><strong><span id="sp_ot_nro"><?php echo $idOrdTra;?></span></strong></td>
       </tr>
       <tr>
         <td>Fecha Documento:</td>
         <td>
         <input type="text" class="tcal clsReq" value="<?php echo $hoy;?>" name="t_ot_fecdoc" id="t_ot_fecdoc" />         </td>
         <td>OT Cliente :</td>
         <td><input name="t_ot_cli" type="text" id="t_ot_cli" size="20" maxlength="20" /></td>
       </tr>
       <tr>
         <td><span class="">Fecha Inicio Prog:</span></td>
         <td><input type="text" id="fecIniProg" name="fecIniProg" class="tcal tcalInput clsReq" value="<?php echo $hoy?>" /></td>
         <td><span class="" >Fecha Fin Prog:</span></td>
         <td><input type="text" id="fecFinProg" name="fecFinProg" class="tcal tcalInput clsReq" value="<?php echo $hoy?>" /></td>
       </tr>
       <tr class="noView">
         <td>Fecha Inicio Real:</td>
         <td><input type="text" id="fecIniReal" name="fecIniReal" class="tcal tcalInput clsReq" value="<?php echo $hoy?>" /></td>
         <td>Fecha Fin Real:</td>
         <td><input type="text" id="fecFinReal" name="fecFinReal" class="tcal tcalInput clsReq" value="<?php echo $hoy?>" /></td>
       </tr>
       <tr>
         <td>Taller :</td>
         <td colspan="3">
           <select name="cb_ce_ot" id="cb_ce_ot" class="clsReq" onchange="getValCentro()" ?> 
           <option title="" value="">Seleccionar</option>
            <?php   
			include('../../Query_Min/getCentros.php'); 
			?>
           </select>
         &nbsp;<span style="font-style:italic;" id="tt_direc">Aqui va la Dirección del Centro seleccionado esta en el attr title del combo de arriba</span>         </td>
    </tr>
       
    
       <tr>
         <td>Almacen de Materiales:</td>
         <td><select  name="cb_ot_alm" id="cb_ot_alm">
         <option value="">Seleccionar</option>
         <?php 
		 $combo = '';
		include('../../Query_Min/getAlmacenes.php');
		echo $combo;
		 ?>
         </select>
         </td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
       </tr>
      <tr>
     <td colspan="4">&nbsp;        </td>
   </tr>
   
             <tr>
               <td colspan="2" class="labelf" valign="top">
               
               <table width="100%" border="0" id="tbl_ot_cli" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4"><strong>Datos del Cliente</strong></td></tr>
   <tr>
     <td class="labelf">&nbsp;</td>
     <td><input name="rb_c1" type="radio" id="rb_c1" value="rb_c1" checked="checked" />
&nbsp;Por C&oacute;digo&nbsp;&nbsp;
<input type="radio" name="rb_c1" id="rb_c2" value="rb_c2" />
&nbsp;Por DNI/RUC/CE&nbsp;&nbsp; </td>
     <td></td>
     <td></td>
   </tr>
   <tr>
                 <td class="labelf">C&oacute;digo<span class="obligatorio">*</span></td>
                 <td><input  type="text" class="clsReq" onchange="inputCliOT()" name="idCli" id="ClientID" size="15" maxlength="12" />
                     
                     <input type="button" id="btn-find-cli" onclick="searchOTCli();" value="[ ... ]" />                                    </td>
                     <td></td>
                     <td></td>                     
              </tr>
              <tr>
                 <td class="labelf">Nombre/Rz.Social :</td>
                 <td><input  type="text" name="ClientNom" id="ClientNom" size="40" disabled="disabled" class="disabled"  /> </td>
                                      <td></td>
                     <td></td>    
              </tr>
              <tr>
                 <td class="labelf">Apellidos</td>
                 <td><input  type="text" name="ClientApell" id="ClientApell" size="40" disabled="disabled" class="disabled"  /> </td>
                                      <td></td>
                     <td></td>
  </tr>
              <tr>
                <td class="labelf">RUC/DNI</td>
                <td><input name="ClientNif"  type="text" disabled="disabled" class="disabled" id="ClientNif" size="20" maxlength="12"  /></td>
                <td></td>
                <td></td>
              </tr>
              <tr>
                <td class="labelf">Dirección</td>
                <td><input name="ClientDir"  type="text" disabled="disabled" class="disabled" id="ClientDir" size="60" maxlength="80"  /></td>
                <td></td>
                <td></td>
              </tr>
</table>               </td>
               <td colspan="2" valign="top">
               <table width="100%"  border="0" id="tbl_ot_vlc" cellspacing="0" cellpadding="0">
  <tr>
<td colspan="4"><strong>Datos del Vehículo</strong></td></tr>
             <tr>
               <td class="labelf" >&nbsp;</td>
               <td colspan="3" >
                 <input name="rb_s1" type="radio" id="rb_s1" class="rb_s1" value="rb_s1" checked="checked" />
                 &nbsp;Por Serie&nbsp;&nbsp;                
                 <input type="radio" name="rb_s1" id="rb_s2" class="rb_s2" value="rb_s2" />&nbsp;Por Placa&nbsp;&nbsp;               </td>
             </tr>
             <tr>
              <td class="labelf" >Serie<span class="obligatorio">*</span></td>
              <td colspan="3" ><input class="clsReq a" type="text" name="VehID" id="VehID" size="18" maxlength="10" value="" onchange="inputVlcOT()"  />
                <span style="padding-left:25px">
                <input type="button" id="btn-find-veh" class="search" value="[ ... ]"  onclick="searchVlcOt()" />
               </span> </td>
            </tr>
             <tr>
              <td class="labelf" style="padding-left:0px">Marca / Modelo</td>
              <td colspan="3"><input  type="text" name="desModel" id="desModel" size="58" disabled="disabled" class="disabled b"/>
                  <input type="hidden" name="MarcaID" id="MarcaID" /> 
                  <input type="hidden" name="ModelID" id="ModelID" />              </td>
             </tr>
             <tr>
               <td>Placa</td>
               <td><input  type="text" name="desNumPla" id="desNumPla" size="18" disabled="disabled" class="disabled c" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
             <tr>
               <td class="labelf">Num Motor</td>
               <td><input  type="text" name="desNumMot" id="desNumMot" size="18" disabled="disabled" class="disabled d" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
             <tr>
               <td>Combustible</td>
               <td>
               <!-- <div style="background-color:#E2730E;border-right:1px solid #000;width:50%;position:relative;height:100%;" id="d_combu">&nbsp;</div>-->		

               <table id="tbl_com" style="cursor:pointer;" cellpadding="0" width="100" height="100%" cellspacing="0" border="1" rules="all">
               <tr>               
               <td id="co1" onclick="selCO(this)">&nbsp;</td>
               <td id="co2" onclick="selCO(this)" >&nbsp;</td>
               <td id="co3" onclick="selCO(this)">&nbsp;</td>
               <td id="co4" onclick="selCO(this)">&nbsp;</td>
               <td id="co5" onclick="selCO(this)">&nbsp;</td>
               <td id="co6" onclick="selCO(this)">&nbsp;</td>               
               </tr>
               </table>			   </td>
                
               <td>&nbsp;</td>
               <td>&nbsp;</td>
  </tr>
</table>               </td>
             </tr>
             <tr>
               <td colspan="4">&nbsp;</td>
             </tr>
             <tr>
               <td colspan="2"><strong>Datos de Facturación</strong></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
             <tr>
             <td>Fecha Plan Factura:</td><td><input name="t_ot_fecfac" type="text" class="tcal clsReq" id="t_ot_fecfac" value="<?php echo $hoy;?>" size="15" maxlength="10" /></td>
              <td>Cond.Venta:</td>
              <td>
                <select name="cb_ot_cvta" id="cb_ot_cvta">
                 <?php 
				 $cond_vta='';
	include('../../Query_Min/getCondVenta.php');
	?>
                </select>              </td>
            </tr>
            <tr>
              <td>Tipo</td>
              <td>
                <input name="radio_ot" type="radio" id="rb_ot_bol" value="rb_ot_bol" checked="checked" />&nbsp;Boleta&nbsp;&nbsp;
                <input type="radio" name="radio_ot" id="rb_ot_fac" value="rb_ot_fac" />&nbsp;Factura&nbsp;              </td>
              <td>Moneda:</td>
              <td>
                <select name="cb_ot_mon" type="text" onchange="/*checkMonedaOT()*/" class="clsReq" id="cb_ot_mon" size="1" maxlength="4">
                <option value="PEN">PEN - Nuevos Soles</option>
                <option value="USD">USD - Dólares Americanos</option>                               
                </select>              </td>
            </tr>
            <tr>
              <td>Texto Documento/Vendedor :</td>
              <td colspan="3">
                <input name="t_ot_txt" type="text" id="t_ot_txt" size="60" maxlength="50" />              </td>
             </tr>
          </table>
</div>     </td>
   </tr>
   <tr>
     <td colspan="4">&nbsp;</td>
   </tr>
   <tr>
   <td colspan="4">
   			
<div id="d_dat_srv">
<?php 
include 'getOtDetalles.php';
?>
</div>
</td>
   </tr>
   <tr>
      <td colspan="4">
      <div  id="td_ot_docs">
<?php
$order = ''; 
if ($found){
	$orden = $idOrdTra;
	$_POST['doc'] = $idOrdTra;
	$_POST['td'] = 'O';
	include ('../Listas/getNextDocs.php');
}
?>
</div>
</td>
   </tr>
   
   <?php if($opc<=1){ ?>

  <?php }else{ ?>
  <script type="text/javascript">
       $(function(){
		 $('.obligatorio').html('');   
		 $('.obligatorio').removeClass('obligatorio'); 
	   }); 
	   
    </script>
  <?php }?>
</table>
</form>


<script type="text/javascript">


<?php
   if($found ){
   ?>  
   GEBI('cb_sts_ot').value = '<?php echo $edoOrdTra;?>';
   GEBI('t_ot_fecdoc').value = '<?php echo $fecdoc;?>';
   GEBI('fecIniProg').value = '<?php echo $fecIniProg;?>';
   GEBI('fecIniReal').value = '<?php echo $fecIniReal;?>';
   GEBI('fecFinProg').value = '<?php echo $fecFinProg;?>';
   GEBI('fecFinReal').value = '<?php echo $fecFinReal;?>';
   GEBI('ClientID').value = '<?php echo $codCli;?>';
   GEBI('ClientNom').value = '<?php echo $nomCli;?>';
   GEBI('ClientApell').value = '<?php echo $apell;?>';
   GEBI('ClientNif').value = '<?php echo $nifCli;?>';
   GEBI('ClientDir').value = '<?php echo $dirCli;?>';
   GEBI('VehID').value = '<?php echo $codVeh;?>';                      
   GEBI('desModel').value = '<?php echo $desMar;?>';                      
	GEBI('desNumMot').value = '<?php echo $numMot;?>';                     
	GEBI('desNumPla').value = '<?php echo $numPla;?>';                  
	GEBI('t_ot_fecfac').value = '<?php echo $fecfac;?>'; 
	GEBI('t_ot_txt').value = '<?php echo $txtot;?>'; 
	//GEBI('cb_ot_cvta').value = '';            
	GEBI('cb_ce_ot').value = '<?php echo $idCentro;?>';   
	GEBI('sp_ot_nro').innerHTML = '<?php echo $orden;?>';
	GEBI('cb_ot_cvta').value = '<?php echo $condv; ?>';
	GEBI('cb_ot_mon').value = '<?php echo $moneda;?>';
	GEBI('t_ot_cli').value = '<?php echo $otCli;?>';	
	getValCentro();             

	fillCo('<?php echo $ctdComb;?>');
    var dtitle=$('#d_title').text();
	 noEditOt();
//    $('#d_title').text(  );
<?php	   
   }
   else{
?>
  $('#d_title').text( $('#title_h').val() );
<?php	          }
?>	

addItemServ();

$('#sp_back').click(function(){
	var _datos=$('#frmAdOrdTrab').serializeArray();			
    loadPage('Mantenimientos/OrdTrabajo/MantOrdTrabajo.php',_datos);	
});

function loadOTCli(objc){
GEBI('ClientID').value = objc.cod;
GEBI('ClientNom').value = (objc.nom);
GEBI('ClientApell').value = (objc.ape);
GEBI('ClientDir').value = objc.dir;
GEBI('ClientNif').value = objc.nif;
closePopup();
}

function addItemServ(){
     			
		var nueva_fila=$('#tbl_otserv tbody .trLast').clone();
		nueva_fila.removeClass('noView');
		nueva_fila.removeClass('trLast');
		nueva_fila.removeClass('deleted');
		//nueva_fila.find(".txt-txsrv").addClass("clsReq");
        $("#tbl_otserv tbody").append(nueva_fila);	
}

function deleteItem(obj){
		obj = $(obj);
       var fila=obj.parent().parent();
	   fila.addClass('deleted');
	   var cls=obj.attr('alt');	 
       fila.addClass('noView');
	   loadTemArt();
	
}

function loadTemArt(_objitem){
    	
	 var _sizeServ=0;	
	 var _strSev='';
	 var objitem=_objitem;
     $('#tbl_otserv tbody tr').not(".trLast").each(function(){
	 	 var th = $(this);
		 if (th.hasClass('deleted')){
		 return;
		 }
		 var desc=th.find('.txt-txsrv').valx();
		 
		 if( ($.trim(desc)!='') && ($.trim(desc)!= "No Existe") ) {
		 	//alert(th.find('.txt-idserv').valx());
			 _strSev+=th.find('.txt-idserv').valx()+",";
			 _sizeServ++;
		 }
		               
	 });
	 
	 _strSev = _strSev.substring(0,_strSev.length-1);
	 //alert(_strSev+"  "+_sizeServ);
	 
	 $('#DivListArt').loadppd('Mantenimientos/OrdTrabajo/listArtOt.php',
	 {
		 strServ:_strSev,
		 sizeServ:_sizeServ
     },function(resultado){
		//$('#DivListArt').html(resultado); 
		//alert();
		if (objitem!=null && objitem != 'undefined'){
		//objitem.etxtLoad();
		}
	 });
		 
	   
}


$('#btn-save').click(function(){
			
	if (!$("#frmAdOrdTrab").checkInput()){
	return;
	}		
		
	var strsv="";
	var items=1;
	var impot=0;
	$('#tbl_otserv tbody tr').not(".trLast").each(function(){
		var fila = $(this);
		var srv = fila.find('.txt-idserv');
		var id_srv = srv.valx();		
		
		if (srv.attr('title')!=id_srv){
		fila.remove();
		return;
		}
		
		if (fila.hasClass('deleted')){
		id_srv = 'DEL';
		}
		
		var it_srv = pInt(fila.find('.txt-itm').html());
		
		
		var no_srv = fila.find('.txt-txsrv').valx();
		var pr_srv = fila.find('.txt-psrv').valx();
		var mon_srv = fila.find('.mon-item').valx();
		//var moneda_srv = fila.find('
		
		strsv = strsv + it_srv+'|'+id_srv+'|'+no_srv+'|'+pr_srv+'|' + mon_srv+'#';
		
		impot+=pFloat(pr_srv);

    });
	
	var _datosfm=$('#frmAdOrdTrab').obj('name');
	_datosfm.oper = 'save';
	_datosfm.items = strsv;
	_datosfm.ctdcomb =  getSelCo();		
	sendData('Mantenimientos/OrdTrabajo/grabar.php',_datosfm
	,function(resultado){
	});
	

	
	
});


 
 
 function getValCentro(){
	  var direc=$("#cb_ce_ot option:selected").attr('title');	
	  $('#tt_direc').text(direc);
 }
 

function nuevaOT(){

loadPage("Mantenimientos/OrdTrabajo/adicionar.php",{ new : true }); 
 
}


$('#t_nro_ot').keypress(function(event){
	  
	  if(event.which==13){
		 $('#opcion').val(1);
		 $('#idOrdTra').val($(this).val());
    	 $('#accion').val('Modificar');
		 var _datos=$('#frmAdOrdTrab').obj('name');
		 _datos.oper = 'view';	
         loadPage("Mantenimientos/OrdTrabajo/adicionar.php",_datos);
         return false; 
	  }
	  
	  
	  
});

function loadOTSrv(srv){
	var fila = $(ses01).parent().parent().parent();	
	var moneda = GEBI('cb_ot_mon').value;
	//if (srv.mon == moneda){
	var txt = fila.find('.txt-idserv').attr('title',srv.id).val(srv.id).focus();
	fila.find('.txt-txsrv').valx(srv.nom);	
	fila.find('.txt-psrv').val(srv.pre);
	fila.find('.mon-item').valx(srv.mon);
	loadTemArt(txt);
	/*
	}
	else {
	loadTemArt(null);
	showError('Moneda de servicio no coincide con Moneda de Documento');
	}
	*/
	ses01 = null;
}

function loadOTVlc(veh){
	/*
	serie : ser,
				motor : mot,
				placa : pla,
				marca : mar
	*/
	closePopup();
//	closexPopup();
	GEBI('VehID').value = veh.serie;
	GEBI('desNumPla').value = veh.placa;
	GEBI('desNumMot').value = veh.motor;
	GEBI('desModel').value = veh.marca;
}

function searchOTCli(){
	loadPopup({ url : 'Consultas/findCliente.php', params : { return : 'loadOTCli' } });
}

function searchVlcOt(){
	loadPopup({ url : 'Consultas/ListVehiculos.php', params : { return : 'loadOTVlc', 'select' : 'X' } });
}


function searchSrvOT(btn){
	ses01 = btn;
	if($(btn).parent().parent().find('.txt-idserv').prop('tagName')=='INPUT'){
	loadPopup({ url : 'Consultas/LstServicios.php', params : { return : 'loadOTSrv', 'select' : 'X' , oper : 'list'} });
	}
}


function inputCliOT(){
	var code = GEBI('ClientID').value;
	var nif = code;
	code = $.trim(code);
	
	if (code==''){
	$("#tbl_ot_cli input[type=text]").val('');
	return;
	}
	
	$("#ClientID").txtLoad();
	
	var option = '';
	if (GEBI('rb_c1').checked){
	option = 'C';
	nif = '';
	}
	if (GEBI('rb_c2').checked){
	option = 'D';
	nif = 'X';
	}
	
	$.post('Query_Min/getDatCliente.php',{
		t_option : option,
		t_codcli : code,
		nif : nif,
		field : 'venta'
	},function(obj){
		//alert(obj);
		$("#ClientID").etxtLoad();
		obj = eval("("+obj+")");
		
		if (obj.cod==''){
			GEBI('ClientID').value = '';
			var crear = confirm('El Codigo de Cliente no existe, ¿Desea crear un cliente?');
			loadOTCli(obj);
			if (crear){
			loadPopup({ url : 'Mantenimientos/MantCli.php',params : { callback : 'loadOTCli'}});
			}
		}
		else {
			loadOTCli(obj);
		}
	});
}


function inputSrvOT(obj){
	var code = obj.value;
	code = $.trim(code);
	var fila = $(obj).parent().parent();
	
	if (code==''){
	fila.find('.txt-txsrv').valx('No existe');
	fila.find('.txt-psrv').html('');
	fila.find('.mon-item').html('');
	return;
	}
	
	obj = $(obj);
	obj.txtLoad();
	
	 $.post('Mantenimientos/OrdTrabajo/obtDatServ.php',
	    {
			idServ:obj.valx()
	    }
	   ,function(resultado){
		     
			var objs=eval("("+resultado+")");
			//alert($(this).html());			
			loadTemArt(obj);
   		    obj.etxtLoad();
			if (objs.id > 0) {
			//obj.attr('title',objs.id);
			ses01 = obj;
			loadOTSrv(objs);
			}
			$('#btn-add-item').focus();
			
	   });
	
}


function inputVlcOT(){
	var code = GEBI('VehID').value;
	code = $.trim(code);
	
	if (code==''){
	$("#tbl_ot_vlc input[type=text]").val('');
	return;
	}
	
	$("#VehID").txtLoad();
	
	var option = '';
	if (GEBI('rb_s1').checked){
	option = 'S';
	}
	if (GEBI('rb_s2').checked){
	option = 'P';
	}
	
	$.post('Query_Min/getDatVehiculo.php',{
		t_option : option,
		t_code : code
	},function(obj){
		//alert(obj);
		$("#VehID").etxtLoad();
		obj = eval("("+obj+")");
		
		if (obj.serie==''){
			GEBI('VehID').value = '';
			var crear = confirm('La serie de vehículo no existe, ¿desea crear un vehículo?');			
			if (!crear){
			loadOTVlc(obj);
			}
			else {
				loadPopup({ url : 'Mantenimientos/MantVeh.php', params : { 'callback' : 'loadOTVlc' } });
			}
			
		}
		else {
			loadOTVlc(obj);
		}
	});
}

function saveFactOt(){
	
	var td = '';
	if (GEBI('rb_ot_bol').checked){
	td = '1';
	}
	else if (GEBI('rb_ot_fac').checked){
	td = '2';
	}
	
	sendData('Mantenimientos/OrdTrabajo/factOrden.php',
		{ 
		oper : 'fact',
		fecha : GEBI('t_ot_fecfac').value, 
		tdoc : td,
		txt : GEBI('t_ot_txt').value,
		cvta : GEBI('cb_ot_cvta').value,
		ot : GEBI('sp_ot_nro').innerHTML 
		}
	);
}

function getSelCo(){
	var mx = 0;
	$("#tbl_com .clsFill").each(function(){
		var id = this.id.substr(2,3);
		if (id>mx){
		mx = id;
		}
	});
	return mx;
}

function noEditOt(){
	$("#frmAdOrdTrab input, #frmAdOrdTrab select, #frmAdOrdTrab textarea").disable();
}

function editOT(){
	$("#frmAdOrdTrab input, #frmAdOrdTrab select, #frmAdOrdTrab textarea").enable();
}

function updPosOt(ot){
}

function checkMonedaOT(){
	
	var mon = GEBI('t_monot').value;

	$('#tbl_otserv tbody tr').not(".trLast").each(function(){
		var fila = $(this);
		var mon_srv= fila.find('.mon-item');
			if (mon_srv != mon){
				fila.remove();
			}		
		});
}

function fillCo(n){
	//alert(n);
	$("#tbl_com td").removeClass('clsFill');
	for(x=1;x<=n;x++){
		$("#co"+x).addClass('clsFill');
	}
}

function  selCO(obj){
	fillCo(obj.id.substr(2,3));
}

function updOtDocs(orden){
	if (pInt(orden)>0){
		$("#td_ot_docs").loadx('Mantenimientos/Listas/getNextDocs2.php',{ orden : orden});
	}
}

function doOtMigo(){
	var ot = pInt(GEBI('sp_ot_nro').innerHTML);
	if (ot>0){
		sendData("Mantenimientos/OrdTrabajo/grabar.php",{ oper : 'migo' , ot : ot});
	}
}
</script>

